<?php

class Store_Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{

	protected $_name = 'store';

	function _initAcl()
	{
		$registry = Zend_Registry::getInstance();
		/**
		 * @var $acl Zend_Acl
		 */
		$acl = $registry->get('acl');
		$this->_initIndexAcl($acl);
		$this->_initStoreAcl($acl);
		$this->_initCateogryAcl($acl);
		$this->_initProductAcl($acl);
		$this->_initShareAcl($acl);
        $this->_initCartAcl($acl);
	}
	
	/**
	 *
	 * @param Zend_Acl $acl
	 */
	private function _initIndexAcl($acl)
	{
		$resource_name = $this->_name . ':index';
		$acl->addResource($resource_name);
		$arrGuest = array(
			'index',
		);
		$arrUser = array_merge(
				array(
                    'notify'
				), $arrGuest
		);
		$acl->allow(Core_Role::ROLE_GUEST, $resource_name, $arrGuest);

		$acl->allow(Core_Role::ROLE_USER, $resource_name, $arrUser);		
	}

	private function _initStoreAcl($acl)
	{
		$resource_name = $this->_name . ':store';
		$acl->addResource($resource_name);
		$arrGuest = array(
			'index'
		);
		$arrUser = array_merge(
				array(
					'index',
					'create',
					'edit',
					'show',
					'hide',
					'list',
					'delete',
					'downloadcss'
				), $arrGuest
		);
		$acl->allow(Core_Role::ROLE_GUEST, $resource_name, $arrGuest);

		$acl->allow(Core_Role::ROLE_USER, $resource_name, $arrUser);
	}
	
	private function _initCateogryAcl($acl)
	{
		$resource_name = $this->_name . ':category';
		$acl->addResource($resource_name);		
		$arrUser = array(
						'index',
						'create',
						'delete',
						'edit',
						'move'
					);
		$acl->allow(Core_Role::ROLE_USER, $resource_name, $arrUser);
	}
	
	private function _initShareAcl($acl)
	{
		$resource_name = $this->_name . ':share';
		$acl->addResource($resource_name);		
		$arrGuest = array(
						'index',
						'product',
						'store',
					);
		$acl->allow(Core_Role::ROLE_GUEST, $resource_name, $arrGuest);
	}
	
	private function _initProductAcl($acl)
	{
		$resource_name = $this->_name . ':product';
		$acl->addResource($resource_name);
		$arrGuest = array(
			'get-system-categories',
			'get-custom-categories',
			'create-category'
		);
		$arrUser = array(
			'index',
			'create',
			'delete',
			'edit',
            'list',
            'hide',
            'show',
			'send'
		);
		$acl->allow(Core_Role::ROLE_USER, $resource_name, $arrUser);
		$acl->allow(Core_Role::ROLE_GUEST, $resource_name, $arrGuest);
	}
    
    private function _initCartAcl($acl)
	{
		$resource_name = $this->_name . ':cart';
		$acl->addResource($resource_name);		
		$arrUser = array('list', 'detail', 'mark', 'note', 'important');
		$acl->allow(Core_Role::ROLE_USER, $resource_name, $arrUser);
	}
}

